package com.edu.modules.baseinfo.dao;

import com.edu.modules.baseinfo.model.LessonRecord;
import com.sari.common.persistence.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by lab on 2016/7/15.
 */
@Repository
public class LessonRecordDao extends BaseDao {

	public List<LessonRecord> getLessonRecordList(String studentId){

		String sql = "select a.LessonRecord_id,a.LessonRecord_name,a.LessonRecord_url,a.score,a.comment," +
				"a.create_time,a.update_time,b.lesson_name,b.lesson_class from t_LessonRecord a, " +
				"d_lesson b where a.lesson_id = b.lesson_id and a.student_id = ?";

		return super.findList(sql,LessonRecord.class,studentId);
	}

	public List getLessonRecordByPage(String lessonName,String lessonClass,String teacherName,
									  String subject,String startTime,String endTime,int offset,int limit){

		String sql = "select * from t_lesson_record where 1=1";
		if(!lessonName.equals("")){
			sql += " and lesson_name like '%"+lessonName+"%'";
		}
		if(!teacherName.equals("")){
			sql += " and teacher_name like '%"+teacherName+"%'";
		}else if(!lessonClass.equals("")){
			sql += " and lesson_class like '%"+lessonClass+"%'";
		}
		if(!subject.equals("")){
			sql += " and subject like '%"+subject+"%'";
		}
		if((!startTime.equals(""))&&(!endTime.equals(""))){
			sql += " and date_time between '"+startTime+"' and '"+endTime+"'";
		}
		sql +=" ORDER BY date_time limit ?,?";

		return super.listBySql(sql,offset,limit);
	}

	public int getLessonRecordCounts(String lessonName,String lessonClass,String teacherName,
									 String subject,String startTime,String endTime){

		String sql = "select count(*) from t_lesson_record where 1=1";
		if(!lessonName.equals("")){
			sql += " and lesson_name like '%"+lessonName+"%'";
		}
		if(!teacherName.equals("")){
			sql += " and teacher_name like '%"+teacherName+"%'";
		}
		if(!lessonClass.equals("")){
			sql += " and lesson_class like '%"+lessonClass+"%'";
		}
		if(!subject.equals("")){
			sql += " and subject like '%"+subject+"%'";
		}
		if((!startTime.equals(""))&&(!endTime.equals(""))){
			sql += " and date_time between '"+startTime+"' and '"+endTime+"'";
		}

		return super.listSqlCount(sql);
	}
}
